<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        let name = "allen";
        let gender = "man";
        let age = "18";
        let obj = {
            name, skill() {
                console.log("我爱你，塞北的雪");
            }
        }
        let obj1 = {
            gender
        }
        let obj2 = {
            age
        }
        //assgin方法 三个对象合为一
        let obj3 = Object.assign(obj, obj1, obj2);
        console.log(obj);
        console.log(obj1);
        console.log(obj2);
        console.log(obj3);

        //对象的浅拷贝
        let obj4 = {
            name:"张三",
            age:"18",
            gender:"女",
            hobbies:["吃","喝","玩"]
        }
        let obj5=Object.assign({},obj4);
        // console.log(obj4);
        // console.log(obj5);
        obj4.name="李四";
        console.log(obj4);
        console.log(obj5);
        //上述是浅拷贝，不会互相影响
        obj4.hobbies[0]="哈哈"
        console.log(obj4);
        console.log(obj5);
        //改变内容是深层拷贝，所以无法解决问题
        
        console.log(Object.keys(obj4));
        console.log(Object.values(obj4))

        //JSON
        let obj6={
            name:"张三",
            age:18,
            gender:"男",
            skill:["坑","蒙","拐","骗"]
        }
        //1.将对象压缩为json字符串
        let jsonStr=JSON.stringify(obj6);
        console.log(jsonStr);
         //2.将json字符串 解压为 js数据
        let obj7=JSON.parse(jsonStr);
        console.log(obj7);
        //使用json方法 实现深拷贝
        let obj8 = {name:"李四",age:"18",skill:["吃","喝","玩","乐"]};
        let jStr=JSON.stringify(obj8);
        let obj9=JSON.parse(jStr);
        obj8.name="张三";
        console.log(obj8,obj9);
        
        
    </script>
</body>

</html>